import requests
import config

import parser
import saver

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    response = requests.get(config.base_url)
    response.encoding = 'utf-8'
    # 获取地区列表页面中所有可解析的 URL
    parse_url_list = parser.parseBasePage(response.text)

    items = []  # 初始化 item 列表
    # 解析每个地区对应的 URL
    print('===== School Fetching Start =====')
    for parse_url in parse_url_list:
        region_response = requests.get(parse_url)
        region_response.encoding = 'utf-8'
        region_result_list = parser.parseRegionPage(region_response.text)
        items.extend(region_result_list)

    saver.save_to_excel(item_list=items)

    print('===== School Fetching Success =====')
